package com.example.rwq_test.delayQueue;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

/**
 * @Description 延迟任务
 *
 * @Author renweiqiang
 * @Date 2024/5/10 下午6:25
 */
public class DelayedTask implements Delayed {
    private String message;
    private long delayTime;

    public DelayedTask(String message, long delayTime) {
        this.message = message;
        this.delayTime = System.currentTimeMillis() + delayTime;
    }

    @Override
    public long getDelay(TimeUnit unit) {
        return delayTime - System.currentTimeMillis();
//        long diff = delayTime - System.currentTimeMillis();
//        return unit.convert(diff, TimeUnit.MILLISECONDS);
    }

    @Override
    public int compareTo(Delayed o) {
        return Long.compare(this.delayTime, ((DelayedTask) o).delayTime);
    }

    public String getMessage() {
        return message;
    }
}
